package com.mde.test;

import java.util.ArrayList;
import java.util.List;

import org.json.*;

import com.mde.util.Point;

public class Processor {

	public static void process(String object) {	
		outputPoints(object);
		Counter.restoreInced();		
		Incer.inc();
	}
	
	private static void outputPoints(String pointsString) {
		try {
			List<Point> points = getPointsList(pointsString);
			points.stream().forEachOrdered(p -> System.out.println(p.getX() + " " + p.getY()));
			System.out.println("OK");
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	private static List<Point> getPointsList(String pointsString) throws JSONException {
		List<Point> points = new ArrayList<>();
		JSONArray arr = new JSONObject("{ array : " + pointsString + "}").getJSONArray("array");
		for (int i = 0; i < arr.length(); ++i) {
			JSONObject obj = new JSONObject(arr.get(i).toString());
			points.add(new Point(obj.getDouble("x"), obj.getDouble("y")));				
		}
		return points;
	}
	
}